package com.his.his_system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.his.his_system.common.util.ResultAdvice;
import com.his.his_system.controller.VisitController.DefaultBean.*;
import com.his.his_system.controller.VisitController.YxyTodo;
import com.his.his_system.domain.*;
import com.his.his_system.mapper.DefaultMapper;
import com.his.his_system.service.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class DefaultServiceImpl implements DefaultService {

    @Resource
    private DefaultMapper defaultMapper;

    @Resource
    private DzmPatientService dzmPatientService;

    @Resource
    private DzmHisCareOrderService dzmHisCareOrderService;

    @Resource
    private DzmHisCareOrderSubService dzmHisCareOrderSubService;

    @Resource
    private DzmHisCarePkgService dzmHisCarePkgService;

    @Resource
    private DzmHisRegistrationService dzmHisRegistrationService;

    @Resource
    private DzmHisCareHistoryService dzmHisCareHistoryService;

    @Resource
    private DzmHisMemberService dzmHisMemberService;

    @Resource
    private DzmHisRegisteredfeeService dzmHisRegisteredfeeService;


    @Resource
    private DzmHisSchedulingWeekService dzmHisSchedulingWeekService;

    @Resource
    private  DzmHisSchedulingService dzmHisSchedulingService;

    @Resource
    private DzmHisSchedulingSubsectionService dzmHisSchedulingSubsectionService;

    @Resource
    private YxyTodo yxyTodo;

    /**
     * 获取排班
     * @param
     * @return
     */
    @Override
    public List<Doctorscheduling> getAllScheduling(String name,Integer ks , String date) {
        return defaultMapper.getAllScheduling(yxyTodo.getHospitalid(),name,ks,date);
    }

    /**
     * 根据医院id获取所有医生
     * @param
     * @return
     */
    @Override
    public  List<DzmHisDefault> getDoctor() {
        List<DzmHisAuthGroup>  list=  defaultMapper.getDoctor(yxyTodo.getHospitalid());
        List<DzmHisDefault> list1 = new ArrayList<>();
        for(DzmHisAuthGroup dzmHisAuthGroup :list){
            List<DzmHisDoctor> list2 = dzmHisAuthGroup.getDzmHisDoctorList();
            List<DzmHisDefault> list3 = new ArrayList<>();
            for(DzmHisDoctor dzmHisDoctor : list2){
                DzmHisDefault dzmHisDefault=   new DzmHisDefault();
                dzmHisDefault.setValue(dzmHisDoctor.getId());
                dzmHisDefault.setLabel(dzmHisDoctor.getTrueName());

                List<DzmHisDefault> list4 = new ArrayList<>();

                DzmHisDefault dzm=   new DzmHisDefault();
                dzm.setValue(1);
                dzm.setLabel("普通号");
                list4.add(dzm);

                DzmHisDefault dzm2=   new DzmHisDefault();
                dzm2.setValue(2);
                dzm2.setLabel("专家号");
                list4.add(dzm2);

                DzmHisDefault dzm3=   new DzmHisDefault();
                dzm3.setValue(3);
                dzm3.setLabel("急诊号");
                list4.add(dzm3);

                dzmHisDefault.setChildren(list4);
                list3.add(dzmHisDefault);
            }
            list1.add(new DzmHisDefault(dzmHisAuthGroup.getId(),dzmHisAuthGroup.getTitle(),list3));
        }

        return list1;
    }

    /**
     * 获取已就诊和未就诊列表
     */
    @Override
    public DzmHisDefault getAllRegister() {
        List<DzmHisRegistration> list=defaultMapper.getAllRegister(yxyTodo.getDoctorid(),"");
        DzmHisDefault dzmHisDefault = new DzmHisDefault();
        List<DzmHisRegistration> falseReg=new ArrayList<>();
        List<DzmHisRegistration> trueReg=new ArrayList<>();
        for(DzmHisRegistration dzmHisRegistration :list){
            if(dzmHisRegistration.getRegistrationStatus()==1) {
                falseReg.add(dzmHisRegistration);
            }
            if(dzmHisRegistration.getRegistrationStatus()==2) {
                trueReg.add(dzmHisRegistration);
            }
        }
        dzmHisDefault.setTrueReg(trueReg);
        dzmHisDefault.setFalseReg(falseReg);
        return dzmHisDefault;
    }


    /**
     * 获取已挂号列表
     */
    @Override
    public List<DzmHisRegistration> getAllRegisters() {
        return  defaultMapper.getAllRegister(yxyTodo.getHospitalid(),"");
    }

    /**
     * 根据患者姓名模糊查询
     * @param patientName 患者姓名
     * @return
     */
    @Override
    public List<DzmHisRegistration> getRegisterlistByname( String patientName) {
        return defaultMapper.getRegisterlistByname(yxyTodo.getDoctorid(),patientName);
    }

    /**
     * 根据患者id查询所有病例
     * @param patientid 患者id
     * @return
     */
    @Override
    public List<DzmHisCareHistory> getAllHistoryByPatientId(Integer patientid) {
        return defaultMapper.getAllHistoryByPatientId(yxyTodo.getHospitalid(),patientid);
    }

    /**
     * 获取可预约的的排班信息
     * @return
     */
    @Override
    public List<Schenduling> getAllSchedulingByNow(Integer did,Integer rid,String name) {
        return defaultMapper.getAllSchedulingByNow(yxyTodo.getHospitalid(),did,rid,name);
    }

    /**
     * 模糊查询获取可预约的的排班信息
     * @return
     */
    @Override
    public List<Schenduling> selectsched(String doctorname ) {
        return defaultMapper.selectsched(doctorname,yxyTodo.getHospitalid());
    }

    /**
     * 获取门诊列表
     * @param
     * @return
     */
    @Override
    public List<DzmHisRegistration> getAllVisit(Integer i,String name,String php,String today) {

        return defaultMapper.getAllVisit(yxyTodo.getDoctorid(),yxyTodo.getHospitalid(),i,name,php,today);
    }

    /**
     * 首页模糊查询
     * @param
     * @param
     * @param i
     * @param namephp
     * @param today
     * @return
     */
    @Override
    public List<DzmHisRegistration> getAllVisit1(Integer i, String namephp, String today) {
        return defaultMapper.getAllVisit1(yxyTodo.getDoctorid(),yxyTodo.getHospitalid(),i,namephp,today);
    }

    /**
     * 开单
     * @param str 患者信息和病例
     * @param list 药品list和检查项目list
     * @return ture/false
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultAdvice billing(String str, String list,Double money) {
        HzInfo hzInfo = ChangeJsonAndObject.jsonChangeObject(str, HzInfo.class);
        System.out.println(list);

        String [] alllist= list.split("%");

        /**
         * 患者信息和病例
         * 1校验患者手机号  没有插入
         * 2插入相关病例
         */
        Integer pid = null;
        Integer rid=0;
            try {
            if(hzInfo.getDisabled()){
                pid = hzInfo.getPatientId();
                rid=hzInfo.getRegistrationId();
                UpdateWrapper<DzmHisRegistration> updateWrapper = new UpdateWrapper();
                updateWrapper.eq("registration_id",rid)
                        .set("registration_status",2);
              if(!dzmHisRegistrationService.update(updateWrapper)){
                  return ResultAdvice.fail("修改挂号表状态失败，请联系管理员");
              }

            }else {
                QueryWrapper<DzmPatient> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("mobile",hzInfo.getPhp());
                if(Objects.isNull(dzmPatientService.getOne(queryWrapper))){
                    //不存在相同手机号
                    DzmPatient dzmPatient = new DzmPatient();
                    insrefPatient(dzmPatient,hzInfo);
                    if(dzmPatientService.save(dzmPatient)){
                        pid=dzmPatient.getPatientId();
                    }else {
                        return ResultAdvice.fail("添加用户失败，请联系管理员");
                    }
                }else {
                    //存在相同手机号
                    return ResultAdvice.fail("该手机号已经注册");
                }
            }

            /**
             * 添加病例
             */
            DzmHisCareHistory dzmHisCareHistory = new DzmHisCareHistory();
            dzmHisCareHistory.setHospitalId(yxyTodo.getHospitalid());
            dzmHisCareHistory.setDoctorId(yxyTodo.getDoctorid());
            dzmHisCareHistory.setPatientId(pid);
            QueryWrapper<DzmHisMember> queryWrapper02 =new QueryWrapper();
            queryWrapper02.eq("uid",yxyTodo.getUserid()).select("department_id");
            DzmHisMember dzmHisMember=dzmHisMemberService.getOne(queryWrapper02);
            if(Objects.isNull(dzmHisMember)){
               return ResultAdvice.fail("插入科室id失败");
            }
            dzmHisCareHistory.setDepartmentId(dzmHisMember.getDepartmentId());
            dzmHisCareHistory.setTypeId(hzInfo.getLeixin());
            dzmHisCareHistory.setIsContagious(hzInfo.getChuanran());
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
            Date date = dateFormat.parse(hzInfo.getFabingdate());
            dzmHisCareHistory.setCaseDate(date);
            dzmHisCareHistory.setAddtime((int)(System.currentTimeMillis()/1000));
            dzmHisCareHistory.setCaseTitle(hzInfo.getZhushu());
            dzmHisCareHistory.setCaseResult(hzInfo.getReslt());
            dzmHisCareHistory.setDoctorTips(hzInfo.getJianyi());
            dzmHisCareHistory.setMemo(hzInfo.getBeizhu());
            if(!dzmHisCareHistoryService.save(dzmHisCareHistory)){
                return ResultAdvice.fail("添加病例失败");
            }

            /**
             * 选中药品集合
             * 3插入数据库
             */
            List<Object> yplist = ChangeJsonAndObject.jsonChangeList(alllist[0], Object.class);
            for(int i = 0 ; i<yplist.size(); i++){
                System.out.println("第"+(i+1)+"药方");
                //1收费总表插入 一个处方一条记录
                DzmHisCarePkg dzmHisCarePkg = new  DzmHisCarePkg();
                dzmHisCarePkg.setHospitalId(1);
                if(!dzmHisCarePkgService.save(dzmHisCarePkg)){
                    return ResultAdvice.fail("添加收费获取id失败");
                }

                List<MedicineList> list1 =  ChangeJsonAndObject.jsonChangeList(yplist.get(i).toString(),MedicineList.class) ;
                //1添加药方获取id
                DzmHisCareOrder dzmHisCareOrder = new DzmHisCareOrder();
                dzmHisCareOrder.setHospitalId(1);
                if(!dzmHisCareOrderService.save(dzmHisCareOrder)){
                    return ResultAdvice.fail("添加药方获取id失败");
                }
                Object yaofangId = dzmHisCareOrder.getId();
                Double chufangmoeny =0.0;
                for(int l =0 ;l<list1.size();l++){
                    //2添加药房详情 关联药房id
                    MedicineList  medicineList= list1.get(l);
                    DzmHisCareOrderSub dzmHisCareOrderSub =new DzmHisCareOrderSub();
                    insrefOrderSub(medicineList,dzmHisCareOrderSub,dzmHisCareOrder.getId(),0);
                    if(!dzmHisCareOrderSubService.save(dzmHisCareOrderSub)){
                        return ResultAdvice.fail("插入药品列表异常");
                    }
                    chufangmoeny=chufangmoeny+(medicineList.getPrice()*medicineList.getSum());
                }

                //2根据收费总表id在修改收费数据
                UpdateWrapper<DzmHisCarePkg> updateWrapper1=new
                        UpdateWrapper<>();
                updateWrapper1.eq("id",dzmHisCarePkg.getId())
                        .set("hospital_id",yxyTodo.getHospitalid())
                        .set("doctor_id",yxyTodo.getDoctorid())
                        .set("patient_id",pid)
                        .set("care_history_id",dzmHisCareHistory.getId())
                        .set("order_code",System.currentTimeMillis()+"")
                        .set("registration_id",rid)
                        .set("amount",chufangmoeny)
                        .set("type_id",0)
                        .set("status",0)
                        .set("addtime",(int)(System.currentTimeMillis()/1000))
                        .set("op_place",1);
                        if(!dzmHisCarePkgService.update(updateWrapper1)){
                            return ResultAdvice.fail("修改收费数据失败");
                        }
                //2根据处方id在修改处方数据
                UpdateWrapper<DzmHisCareOrder> updateWrapper2=new
                        UpdateWrapper<>();
                updateWrapper2
                        .eq("id",yaofangId)
                        .set("hospital_id",yxyTodo.getHospitalid())
                        .set("doctor_id",yxyTodo.getDoctorid())
                        .set("patient_id",pid)
                        .set("care_history_id",dzmHisCareHistory.getId())
                        .set("pkg_id",dzmHisCarePkg.getId())
                        .set("status",0)
                        .set("label","第"+(i+1)+"药方")
                        .set("amount",chufangmoeny)
                        .set("all_amount",money)
                        .set("addtime",(int)(System.currentTimeMillis()/1000));

                        if(!dzmHisCareOrderService.update(updateWrapper2)){
                            return ResultAdvice.fail("处方和药品列表插入失败");
                        }
            }

            /**选中项目集合
             *插入数据库
             */
            List<Object> xmlist = ChangeJsonAndObject.jsonChangeList(alllist[1], Object.class);
            for (int i = 0; i < xmlist.size(); i++) {
                System.out.println("第" + (i + 1) + "检查项目处方");
                //1收费总表插入 一个处方一条记录
                DzmHisCarePkg dzmHisCarePkg = new DzmHisCarePkg();
                dzmHisCarePkg.setHospitalId(1);
                if (!dzmHisCarePkgService.save(dzmHisCarePkg)) {
                    return ResultAdvice.fail("2添加收费获取id失败");
                }
                List<CheckList> list1 = ChangeJsonAndObject.jsonChangeList(xmlist.get(i).toString(), CheckList.class);
                //1添加检查处方获取id
                DzmHisCareOrder dzmHisCareOrder = new DzmHisCareOrder();
                dzmHisCareOrder.setHospitalId(1);
                if (!dzmHisCareOrderService.save(dzmHisCareOrder)) {
                    return ResultAdvice.fail("2添加药方获取id失败");
                }
                Object xmchufangId = dzmHisCareOrder.getId();
                Double chufangmoeny = 0.0;
                for (int l = 0; l < list1.size(); l++) {
                    //2添加药房详情 关联药房id
                    CheckList checkList = list1.get(l);
                    DzmHisCareOrderSub dzmHisCareOrderSub = new DzmHisCareOrderSub();
                    insrefOrderSub(checkList, dzmHisCareOrderSub, dzmHisCareOrder.getId(), 2);
                    if (!dzmHisCareOrderSubService.save(dzmHisCareOrderSub)) {
                        return ResultAdvice.fail("插入检查项目列表异常");
                    }
                    chufangmoeny = chufangmoeny + checkList.getPrice();
                }
                //2根据收费总表id在修改收费数据
                UpdateWrapper<DzmHisCarePkg> updateWrapper1 = new
                        UpdateWrapper<>();
                updateWrapper1.eq("id", dzmHisCarePkg.getId())
                        .set("hospital_id", yxyTodo.getHospitalid())
                        .set("doctor_id", yxyTodo.getDoctorid())
                        .set("patient_id", pid)
                        .set("care_history_id", dzmHisCareHistory.getId())
                        .set("order_code", System.currentTimeMillis() + "")
                        .set("registration_id", rid)
                        .set("amount", chufangmoeny)
                        .set("type_id", 0)
                        .set("status", 0)
                        .set("addtime", (int) (System.currentTimeMillis() / 1000))
                        .set("op_place", 2);
                if (!dzmHisCarePkgService.update(updateWrapper1)) {
                    return ResultAdvice.fail("2修改收费数据失败");
                }
                //2根据处方id在修改处方数据
                UpdateWrapper<DzmHisCareOrder> updateWrapper2 = new
                        UpdateWrapper<>();
                updateWrapper2
                        .eq("id", xmchufangId)
                        .set("hospital_id", yxyTodo.getHospitalid())
                        .set("doctor_id", yxyTodo.getDoctorid())
                        .set("patient_id", pid)
                        .set("care_history_id", dzmHisCareHistory.getId())
                        .set("pkg_id", dzmHisCarePkg.getId())
                        .set("status", 0)
                        .set("label", "第" + (i + 1) + "检查项目")
                        .set("amount", chufangmoeny)
                        .set("all_amount", money)
                        .set("addtime", (int) (System.currentTimeMillis() / 1000));
                if (!dzmHisCareOrderService.update(updateWrapper2)) {
                    return ResultAdvice.fail("检查项目列表插入失败");
                }
            }

            /**
             * 添加附加费
             *
             */
            //添加费用总表
            DzmHisCarePkg dzmHisCarePkg=new DzmHisCarePkg();
            dzmHisCarePkg.setHospitalId(1);
            dzmHisCarePkgService.save(dzmHisCarePkg);

            // 添加处方表
            DzmHisCareOrder dzmHisCareOrder =new DzmHisCareOrder();
            dzmHisCareOrder.setHospitalId(yxyTodo.getHospitalid());
            dzmHisCareOrder.setDoctorId(yxyTodo.getDoctorid());
                dzmHisCareOrder.setPatientId(pid);
                dzmHisCareOrder.setCareHistoryId(dzmHisCareHistory.getId());
                dzmHisCareOrder.setPkgId(dzmHisCarePkg.getId());
                dzmHisCareOrder.setStatus(0);
                dzmHisCareOrder.setLabel("附加费处方");
                dzmHisCareOrder.setAmount(BigDecimal.valueOf(hzInfo.getFjf()+hzInfo.getGhf()));
                dzmHisCareOrder.setAllAmount(BigDecimal.valueOf(money));
                dzmHisCareOrder.setAddtime((int)(System.currentTimeMillis()/1000));
            if(!dzmHisCareOrderService.save(dzmHisCareOrder)){
                ResultAdvice.fail("添加附加费处方失败");
            }


            //添加处方子表
            DzmHisCareOrderSub dzmHisCareOrderSub = new DzmHisCareOrderSub();
            dzmHisCareOrderSub.setFid(dzmHisCareOrder.getId());
            dzmHisCareOrderSub.setTypeId(1);
            dzmHisCareOrderSub.setAmount(BigDecimal.valueOf(hzInfo.getFjf()+hzInfo.getGhf()));
            if(!dzmHisCareOrderSubService.save(dzmHisCareOrderSub)){
                return ResultAdvice.fail("添加附加费失败");
            }

            UpdateWrapper<DzmHisCarePkg> updateWrapper=new UpdateWrapper<>();
            updateWrapper.eq("id",dzmHisCarePkg.getId())
                            .set("hospital_id",yxyTodo.getHospitalid())
                            .set("doctor_id", yxyTodo.getDoctorid())
                            .set("patient_id",pid)
                            .set("care_history_id",dzmHisCareHistory.getId())
                            .set("registration_id",rid)
                            .set("amount",hzInfo.getFjf()+hzInfo.getGhf())
                            .set("status",0)
                            .set("addtime",(int)(System.currentTimeMillis()/1000))
                            .set("op_place",3);
            if(!dzmHisCarePkgService.update(updateWrapper)){
                return ResultAdvice.fail("附加费修改失败");
            }

            return  ResultAdvice.success("测试成功");
        }catch (Exception e) {
           throw  new RuntimeException("开单异常");
        }
    }


    @Override
    public List<HanZhe> getAllRegisterToday2(String namephp) {
        return defaultMapper.getAllRegisterToday2(namephp,yxyTodo.getDoctorid(),yxyTodo.getHospitalid());
    }

    @Override
    public List<HanZhe> getAllyiRegister(String name, String php) {
        return defaultMapper.getAllyiRegister(name,php,yxyTodo.getHospitalid(),yxyTodo.getDoctorid());
    }

    @Override
    public List<DeptList>  getAllDoctorbydepid() {
        List<DzmHisDepartment> departmentList = defaultMapper.getAllDoctorbydepid(yxyTodo.getHospitalid());
        List<DzmHisRegisteredfee>  dzmHisRegisteredfees=dzmHisRegisteredfeeService.list();
        List<DeptList> deptLists = new LinkedList<>();
        for(DzmHisDepartment dep : departmentList){
            DeptList deptList = new DeptList();
            deptList.setDid(dep.getDid());
            deptList.setDname(dep.getDepartmentName());

            List<SelectList> selectLists = new LinkedList<>();
            for(DzmHisDoctor doctor : dep.getDoctorList()){
                SelectList se= new SelectList();
                se.setLabel(doctor.getTrueName());
                se.setValue( doctor.getId());
                List<SelectList> sel= new LinkedList<>();
                for( DzmHisRegisteredfee dzmHisRegisteredfee:dzmHisRegisteredfees){
                    SelectList sll= new SelectList();
                    sll.setValue(dzmHisRegisteredfee.getRegId());
                    sll.setLabel(dzmHisRegisteredfee.getRegisteredfeeName());
                    sel.add(sll);
                }
                se.setChildren(sel);
                selectLists.add(se);
            }
            deptList.setSelectListList(selectLists);
            deptLists.add(deptList);
        }

        return deptLists;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean Scheduling(String datastr) {
        try{
            List<PaiBan>  lplist=   ChangeJsonAndObject.jsonChangeList(datastr, PaiBan.class);
            for(PaiBan paiBan :lplist){
                // 星期及
                Integer i = paiBan.getE();
                //坐班日期
                String date=paiBan.getDate();
                //科室id
                Integer did=paiBan.getDid();
                List<Integer> list = paiBan.getDepDoc();
                Integer doctorid = list.get(0);
                Integer regfeeid = list.get(1);
                //添加Scheduling表
                DzmHisScheduling dzmHisScheduling = new DzmHisScheduling();
                dzmHisScheduling.setPhysicianid(doctorid);
                dzmHisScheduling.setDepartmentId(did);
                dzmHisScheduling.setCompanyId(yxyTodo.getHospitalid());
                dzmHisScheduling.setStartTimeThisWeek(date+": 00:00:00");
                dzmHisScheduling.setEndTimeThisWeek(date+": 23:59:59");
                dzmHisScheduling.setCreateTime((int)(System.currentTimeMillis()/1000));
                if(!dzmHisSchedulingService.save(dzmHisScheduling)){
                    throw new RuntimeException("添加Scheduling表失败");
                }
                for(int l =1 ;l<=3;l++){
                    //添加dzmHisSchedulingSubsection表
                    DzmHisSchedulingSubsection dzmHisSchedulingSubsection = new DzmHisSchedulingSubsection();
                    dzmHisSchedulingSubsection.setSubsectionType(l);
                    dzmHisSchedulingSubsection.setSchedulingId(dzmHisScheduling.getSchedulingId().intValue());
                    if(!dzmHisSchedulingSubsectionService.save(dzmHisSchedulingSubsection)){
                        throw new RuntimeException("添加dzmHisSchedulingSubsection表失败");
                    }
                    //添加dzmHisSchedulingWeek表
                    DzmHisSchedulingWeek dzmHisSchedulingWeek=new DzmHisSchedulingWeek();
                    dzmHisSchedulingWeek.setDate(date);
                    dzmHisSchedulingWeek.setWeek(i);
                    dzmHisSchedulingWeek.setRegisteredfeeId(regfeeid);
                    dzmHisSchedulingWeek.setSchedulingSubsectionId(dzmHisSchedulingSubsection.getSchedulingSubsectionId());
                    if(!dzmHisSchedulingWeekService.save(dzmHisSchedulingWeek)){
                        throw new RuntimeException("添加dzmHisSchedulingWeek表失败");
                    }
                }
            }
        }catch (Exception e){
            throw new RuntimeException("异常");
        }
        return true;
    }

    @Override
    public List<DzmPatient> getAllHistory(String name, String depname) {
        return defaultMapper.getAllHistory(name,depname,yxyTodo.getHospitalid());
    }

    public void insrefPatient(DzmPatient dzmPatient,HzInfo hzInfo){
        dzmPatient.setHospitalId(yxyTodo.getHospitalid());
        dzmPatient.setName(hzInfo.getName());
        dzmPatient.setMobile(hzInfo.getPhp());
        dzmPatient.setUpdateTime((int)(System.currentTimeMillis()/1000));
        if(hzInfo.getSex().equals('男')){
            dzmPatient.setSex(1);
        }else {
            dzmPatient.setSex(2);
        }
        dzmPatient.setIsFinal(0);
        dzmPatient.setAddress(hzInfo.getAddress());
        dzmPatient.setCreateTime((int)(System.currentTimeMillis()/1000));
        dzmPatient.setIsDel(0);
    }

    /**
     *
     * @param medicineList
     * @param dzmHisCareOrderSub
     * @param chufangid
     * @param typeid 0药品  1 附加费  2 检查项目
     */
    public void insrefOrderSub(MedicineList medicineList,DzmHisCareOrderSub dzmHisCareOrderSub,Object chufangid,int typeid){
        dzmHisCareOrderSub.setFid(chufangid);
        dzmHisCareOrderSub.setTypeId(typeid);
        dzmHisCareOrderSub.setGoodsId(medicineList.getYpid());
        dzmHisCareOrderSub.setGoodsName(medicineList.getMedicinesName());
        dzmHisCareOrderSub.setPrice(BigDecimal.valueOf(medicineList.getPrice()));
        dzmHisCareOrderSub.setUnit(medicineList.getUnit());
        dzmHisCareOrderSub.setNum(BigDecimal.valueOf(medicineList.getSum()));
        dzmHisCareOrderSub.setAmount(BigDecimal.valueOf(medicineList.getSum()*medicineList.getPrice()));
    };


    /**
     *
     * @param checkList
     * @param dzmHisCareOrderSub
     * @param typeid 0药品  1 附加费  2 检查项目
     */
    public void insrefOrderSub( CheckList checkList,DzmHisCareOrderSub dzmHisCareOrderSub,Object xmchufangid,int typeid){
        dzmHisCareOrderSub.setFid(xmchufangid);
        dzmHisCareOrderSub.setTypeId(typeid);
        dzmHisCareOrderSub.setGoodsId(checkList.getXmid());
        dzmHisCareOrderSub.setGoodsName(checkList.getXmmc());
        dzmHisCareOrderSub.setPrice(BigDecimal.valueOf(checkList.getPrice()));
        dzmHisCareOrderSub.setUnit(checkList.getXmdanwei());
        dzmHisCareOrderSub.setNum(BigDecimal.valueOf(1));
        dzmHisCareOrderSub.setAmount(BigDecimal.valueOf(checkList.getPrice()));
    };

}
